﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetSysData;

namespace BladeTecWebApplication.Admin
{
	public partial class PrintQuiz : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{

				NetSysData.NetSysData data = new NetSysData.NetSysData();

				int quiz_id;
				QUIZ quiz;
				QUESTION[] questions;
				QUIZ_QUESTION[] quiz_questions;

				try
				{
					quiz_id = Int32.Parse(Request.QueryString["quiz_id"]);
				}
				catch (Exception)
				{
					// show error
					return;
				}

				if (Request.QueryString["quiz_id"] != "")
				{
					quiz = data.GetQuiz(quiz_id);
					if (quiz == null)
					{
						// show error
						return;
					}
				}
				else
				{
					// show error
					return;
				}

				lblQuizTitle.Text = quiz.QUIZ_NAME;
				
				questions = data.GetQuestions();
				quiz_questions = data.GetQuizQuestions(quiz_id);
				foreach (QUESTION q in questions)
				{

					bool questionSelected = false;
					foreach (QUIZ_QUESTION qq in quiz_questions)
					{
						if (qq.QUESTION_ID == q.QUESTION_ID)
						{
							questionSelected = true;
							break;
						}
					}

					if (!questionSelected)
						continue;

					string checkedText = (questionSelected) ? "checked=\"true\"" : "";
					string tableClass = (questionSelected) ? "class=\"\"" : "";

					string tableText = "<table cellpadding=\"0\" border=\"0\" cellspacing=\"0\" width=\"980px\" id=\"questionTable"+q.QUESTION_ID+"\" "+tableClass+"><tr>";
					tableText += "<td style=\"padding-left:10px;width:680px;\">";
					tableText += q.QUESTION_TEXT + "<br />";

					if (q.QUESTION_TYPE == "M")
					{
						tableText += "<ol type=\"a\">";
						foreach (ANSWER a in q.ANSWERs)
						{
							if (a.IS_CORRECT_ANSWER == 1)
							{
								tableText += "<li>" + a.ANSWER_TEXT + " (correct)</li>";
							}
							else
							{
								tableText += "<li>" + a.ANSWER_TEXT + "</li>";
							}
						}
						tableText += "</ol>";
					}
					else
					{
						tableText += "<div style=\"padding-left:10px;\">Short Answer</div>";
					}

					tableText += "</td>";
					tableText += "<td style=\"padding-left:10px;width:100px;\" valign=\"top\">"+q.QUESTION_LEVEL.LEVEL_DESCRIPTION+"</td>";
					tableText += "<td style=\"padding-left:10px;width:200px;\" valign=\"top\">" + q.QUESTION_CATEGORY.CATEGORY_NAME + "</td>";

					tableText += "</tr></table>";

					string controlText = "<div style=\"padding: 10px;margin-bottom:10px;\" class=\"ui-widget ui-widget-content ui-corner-all\" id=\"questionDiv"+q.QUESTION_ID+"\">";
					controlText += "<div class=\"ui-dialog-content ui-widget-content\" style=\"background: none; border: 0;\" id=\"questionDivInner"+q.QUESTION_ID+"\">";
					controlText += tableText;
					controlText += "</div>";
					controlText += "</div>";
					pnlQuestions.Controls.Add(new LiteralControl(controlText));
					
				}

				//hfQuizId.Value = quiz_id.ToString();

			}
		}

	}
}